
class_name CNoticeFlow

extends EventDispatcher

signal UUID_changed(old_value, new_value) 
signal NoticeID_changed(old_value, new_value) 
signal Notice_changed(old_value, new_value) 
signal NoticeType_changed(old_value, new_value) 
signal BeginTime_changed(old_value, new_value) 
signal EndTime_changed(old_value, new_value) 
signal NoticeInterval_changed(old_value, new_value) 
signal NeedLang_changed(old_value, new_value) 
signal NeedNation_changed(old_value, new_value) 
signal NeedPlatform_changed(old_value, new_value) 


var m_tblAlias
var bInited = false
func _init(_uuid)->void:
    self.UUID = _uuid
    self.NoticeID = ''	# 公告id
    self.Notice = ''	# 公告内容
    self.NoticeType = 0	# 公告类型
    self.BeginTime = 0	# 开始时间
    self.EndTime = 0	# 结束时间
    self.NoticeInterval = 0	# 间隔时间（秒）
    self.NeedLang = ''	# 限制语言
    self.NeedNation = ''	# 限制国家
    self.NeedPlatform = ''	# 限制渠道

    self.m_tblAlias = {
 
    }

func UnPack(_bufferStream):
    self.UUID = _bufferStream.ReadInt64()
    self.NoticeID = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_NoticeID)
    self.Notice = _bufferStream.ReadBytes(TableCommonDefine.ECharLen.eCL_Notice)
    self.NoticeType = _bufferStream.ReadUint8()
    self.BeginTime = _bufferStream.ReadUint32()
    self.EndTime = _bufferStream.ReadUint32()
    self.NoticeInterval = _bufferStream.ReadUint32()
    self.NeedLang = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_NeedLang)
    self.NeedNation = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_NeedNation)
    self.NeedPlatform = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_NeedPlatform)

    self.bInited = true


func GetTableName():
    return 'NoticeFlow'

func CopyFrom(other):
    self.NoticeID = other.NoticeID
    self.Notice = other.Notice
    self.NoticeType = other.NoticeType
    self.BeginTime = other.BeginTime
    self.EndTime = other.EndTime
    self.NoticeInterval = other.NoticeInterval
    self.NeedLang = other.NeedLang
    self.NeedNation = other.NeedNation
    self.NeedPlatform = other.NeedPlatform


func OnDataChanged( fieldName, oldValue, newValue):
    if oldValue == newValue:
        return
    
    self.DispatchEvent(fieldName, [self, oldValue, newValue])
    #  Alias
    if self.m_tblAlias[fieldName] != null:
        for i in range(self.m_tblAlias[fieldName].size()):
            self.DispatchEvent(self.m_tblAlias[fieldName][i], [self, oldValue, newValue])

func UnPackField(_fieldId, _bufferStream, _varLen ):
    if _fieldId < 0 or _fieldId == 0xffff:
        var old = CNoticeFlow.new(self.m_UUID)
        old.CopyFrom( self )
        self.UnPack( _bufferStream )
        self.DispatchEvent("CNoticeFlow", [self, old, self])
        return true

    print("UnPackField error tblName = NoticeFlow, className = CNoticeFlow, _fieldId = ", _fieldId)
    # if _fieldId > Fields_NoticeFlowID.size():
    #     var szLog = 'CNoticeFlow.UnPackField  _fieldId(%d) < 0 or _fieldId(%d) > #Fields_NoticeFlowID(%d)' % [_fieldId, _fieldId,  Fields_NoticeFlowID.size()]
    #     print(szLog)
    #     return false

    # Fields_NoticeFlowID[_fieldId].reader( self, _bufferStream, _varLen)

    return true

func AddField(_fieldId, _bufferStream):
    print( "[TABLEDATA] error AddField", "CNoticeFlow", _fieldId )

    
func DelField(_fieldId ):
    print( "[TABLEDATA] error DelField", "CNoticeFlow", _fieldId )

var UUID:
    set(value):
        var old = self.m_UUID
        self.UUID = _value
        self.UUID_changed.emit(old, _value)

    get:
        return self.UUID


var NoticeID:
    set(value):
        var old = self.m_NoticeID
        self.NoticeID = _value
        self.NoticeID_changed.emit(old, _value)

    get:
        return self.NoticeID


var Notice:
    set(value):
        var old = self.m_Notice
        self.Notice = _value
        self.Notice_changed.emit(old, _value)

    get:
        return self.Notice


var NoticeType:
    set(value):
        var old = self.m_NoticeType
        self.NoticeType = _value
        self.NoticeType_changed.emit(old, _value)

    get:
        return self.NoticeType


var BeginTime:
    set(value):
        var old = self.m_BeginTime
        self.BeginTime = _value
        self.BeginTime_changed.emit(old, _value)

    get:
        return self.BeginTime


var EndTime:
    set(value):
        var old = self.m_EndTime
        self.EndTime = _value
        self.EndTime_changed.emit(old, _value)

    get:
        return self.EndTime


var NoticeInterval:
    set(value):
        var old = self.m_NoticeInterval
        self.NoticeInterval = _value
        self.NoticeInterval_changed.emit(old, _value)

    get:
        return self.NoticeInterval


var NeedLang:
    set(value):
        var old = self.m_NeedLang
        self.NeedLang = _value
        self.NeedLang_changed.emit(old, _value)

    get:
        return self.NeedLang


var NeedNation:
    set(value):
        var old = self.m_NeedNation
        self.NeedNation = _value
        self.NeedNation_changed.emit(old, _value)

    get:
        return self.NeedNation


var NeedPlatform:
    set(value):
        var old = self.m_NeedPlatform
        self.NeedPlatform = _value
        self.NeedPlatform_changed.emit(old, _value)

    get:
        return self.NeedPlatform



